/*
 * Gyroscope.h
 *
 *  Created on: 22.11.2012
 *      Author: Michael
 */

#ifndef GYROSCOPE_H_
#define GYROSCOPE_H_

#include "../Interfaces/I2C.h"

#define L3G4200D_ADDR			0xD2

#define WHO_AM_I 				0x0F
#define CTRL_REG1 				0x20
#define CTRL_REG2 				0x21
#define CTRL_REG3 				0x22
#define CTRL_REG4 				0x23
#define CTRL_REG5 				0x24
#define REFERENCE 				0x25
#define OUT_TEMP 				0x26
#define STATUS_REG 				0x27
#define OUT_X_L 				0x28
#define OUT_X_H 				0x29
#define OUT_Y_L 				0x2A
#define OUT_Y_H					0x2B
#define OUT_Z_L 				0x2C
#define OUT_Z_H 				0x2D
#define FIFO_CTRL_REG 			0x2E
#define FIFO_SRC_REG 			0x2F
#define INT1_CFG 				0x30
#define INT1_SRC 				0x31
#define INT1_TSH_XH 			0x32
#define INT1_TSH_XL 			0x33
#define INT1_TSH_YH 			0x34
#define INT1_TSH_YL 			0x35
#define INT1_TSH_ZH 			0x36
#define INT1_TSH_ZL 			0x37
#define INT1_DURATION 			0x38

#define REFTEMP					32

#define dps250Scale				0.00875f
#define dps500Scale				0.0175f
#define dps2000Scale			0.070f

#define dps500Bias				-16.3821f
#define dps2000Bias				-8.684791496320523f

#define GYRO_BUFFER_SIZE			10

#define GYROBIAS				1000

enum gyroRange{
	dps250 = 250,
	dps500 = 500,
	dps2000 = 2000
};

class Gyroscope {
public:
	Gyroscope(I2C *i2c, int range);
	virtual ~Gyroscope();
	int getRawAngularRateZ();
	float getScaledAngularRateZ();
	float getAngularRateZ();
	int getRawTemp();
	int getTemp();

private:
	I2C *i2c;
	float gyroScale;
	float rawBias;

	void write(uint8_t regAddr, uint8_t val);
	uint8_t read(uint8_t regAddr);
};

#endif /* GYROSCOPE_H_ */
